package com.wie.staffhubpro.controller;

import com.wie.staffhubpro.domain.dto.ProjectDTO;
import com.wie.staffhubpro.domain.dto.ProjectEmpDTO;
import com.wie.staffhubpro.domain.entity.Project;
import com.wie.staffhubpro.domain.entity.ProjectDept;
import com.wie.staffhubpro.domain.entity.ProjectDetail;
import com.wie.staffhubpro.domain.entity.Result;
import com.wie.staffhubpro.domain.vo.ProjectVO;
import com.wie.staffhubpro.service.ProjectDeptService;
import com.wie.staffhubpro.service.ProjectEmpService;
import com.wie.staffhubpro.service.ProjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    /**
     * 查询所有项目
     */
    @GetMapping("/list")
    public Result getList() {
        log.info("查询所有项目");
        List<ProjectVO> projectVOList = projectService.listProject();
        return Result.success(projectVOList);
    }

    /**
     * 根据id查询项目
     */
    @GetMapping("/getById")
    public Result getById (@RequestParam Integer projectId) {
        log.info("根据id查询项目: {}", projectId);
        ProjectDetail projectDetail = projectService.getByProjId(projectId);
        return Result.success(projectDetail);
    }

    /**
     * 新增项目
     */
    @PostMapping("/add")
    public Result add (@RequestBody ProjectDTO projectDTO) {
        log.info("新增项目: {}", projectDTO);
        projectService.add(projectDTO);
        return Result.success();
    }

    /**
     * 修改项目信息
     */
    @PostMapping("/alter")
    public Result alter (@RequestBody ProjectDTO projectDTO) {
        log.info("修改项目信息, {}", projectDTO);
        projectService.alter(projectDTO);
        return Result.success();
    }

    /**
     * 给项目添加员工
     */
    @PostMapping("/addEmp")
    public Result addEmp (@RequestBody ProjectEmpDTO projectEmpDTO) {
        log.info("给项目添加员工: {}", projectEmpDTO);
        projectService.addEmp(projectEmpDTO);
        return Result.success();
    }

    /**
     * 从项目中删除员工
     */
    @PostMapping("/delEmp")
    public Result delEmp (@RequestBody ProjectEmpDTO projectEmpDTO) {
        log.info("从项目中删除员工: {}", projectEmpDTO);
        projectService.delEmp(projectEmpDTO);
        return Result.success();
    }

}
